Plotting problem 1 (Intro).mws

1. Plotting data points: A Maple tutorial.

> restart;

Plotting an Expression: the plot( ) command

Example 1:

We use the plot( ) command to plot the graph of 3*x^2-8 for x between - 5 and 5 .

> plot(3*x^2-8,x=-5..5);

[Maple Plot]

Notice that Maple scales the y -axis automatically, choosing a y -scale that shows the entire graph corresponding to the specified domain.  You can override automatic y-scaling by specifying a range for y as well as x. On the next line we have limited the y-range to the interval [-20,40].

> plot(3*x^2-8,x=-5..5,y=-20..40);

[Maple Plot]

If you click on a graph with the left mouse button, the graph is selected and the bottom toolbar options are changed. See the reference diagram below. Now when you click on the graph, the point coordinates of its location are shown. The 1:1 button makes the x -scale and y -scale equal.  Scroll back up to the previous graph and experiment with these features. Try the other graph options as well.

Example 2:

Automatic scaling is a useful feature but there are times when you may want to set the y range manually. For example automatic scaling isn't appropriate for graphs with vertical asymptotes.  Compare the next two graphs. Notice how we have set the limits for y to the interval [-20,20] in the second plot command.

> plot(x/(x-2),x=-5..5);

[Maple Plot]

> plot(x/(x-2),x=-5..5,y=-20..20);

[Maple Plot]

Example 3:

Plot the graph of y = x^3+1-exp(x) over the domain [-8,8]. Choose a y-range that allows you to see the four x-intercepts.  First let's take a look at the plot with automatic scaling of y.

> plot(x^3+1-exp(x),x=-8..8);

[Maple Plot]

The large negative values for y near 8 have forced the vertical scale to be too large to see the x-intercepts clearly. A better view is achieved by setting limits on the y-range.

> plot(x^3+1-exp(x),x=-8..8,y=-5..15);

[Maple Plot]

Exercise 3.1

Plot y = sin(x) over two complete periods.

Student Workspace 3.1

 

Answer 3.1

> plot (sin(x),x=-2*Pi..2*Pi);

[Maple Plot]

Exercise 3.2

Plot y = 3*x^4-6*x^2 over the domain [-10,10] with automatic y scaling. After observing the graph, edit the domain and range so that you can see the x-intercepts clearly. Estimate the x -intercepts with the mouse cursor.

Student Workspace 3.2

 

Answer 3.2

> plot(3*x^4-6*x^2,x);

[Maple Plot]

Notice how large y becomes when x = -10 or x = 10; with automatic y scaling it is difficult to see how the function behaves for x between -2 and 2. In the next plot we restrict the y scale in order to better observe the behavior for small y outputs.

> plot (3*x^4-6*x^2,x=-3..3,y=-5..15);

[Maple Plot]

The x -intercepts are about -1.4, 1.4 and 0.

Plotting Several Expressions

To show more than one graph in the same picture list them in square brackets [ ] separated by commas.

> plot([cos(x),x^2],x=-1..4,y=-4..4);

[Maple Plot]

Notice that each of the graphs is displayed using a different color. You can specify the colors for each function by adding a color option at the end of the command. The colors are assigned in the same order as the functions. Note that the colors must also be listed in a square bracket [ ] . Here is an example.

> plot([cos(x),x^2],x=-1..5,y=-4..4,color=[blue,black]);

[Maple Plot]

Here are the colors available in Maple:  aquamarine, black, blue, navy, coral, cyan, brown, gold, green, gray, grey, khaki, magenta, maroon, orange, pink, plum, red, sienna, tan, turquoise, violet, wheat, white, yellow.

Exercise 3.3

Graph the functions y = x^2-5*x+6 and y = 1/((x-2)^2) together. Experiment with different y ranges so that complete pictures of both graphs are shown.

Student Workspace 3.3

 

Answer 3.3

> y1:=x^2-5*x+6;

y1 := x^2-5*x+6

> y2:=1/(x-2)^2;

y2 := 1/((x-2)^2)

> plot([y1,y2],x=-3..8,y=-1..6);

[Maple Plot]

Plotting points

The plot command can also plot one or more points.

Example 1:

Plot the point (2,3).  Note in the following line that we use two sets of square brackets.

> plot([ [2,3] ],style=point);

[Maple Plot]

Example 2:

We can control the size of the x and y ranges shown by adding these to the command as in the next line.

> plot([ [2,3] ],x=-7..7,y=-7..7,style=point);

[Maple Plot]

Example 3:

To graph more than one point list them in the plot command. Note the commas. Remember square brackets for each point and an extra pair of square brackets surround the list.

> plot([ [2,3],[-2,5],[1,-4] ],x=-7..7,y=-7..7,style=point);

[Maple Plot]

Example 4:

Changing style to "line" connects the points in the order listed.

> plot([ [2,3],[-2,5],[1,-4] ],x=-7..7,y=-7..7,style=line);

[Maple Plot]

Example 5:

Optional extensions can be used to specify point color and symbol (e.g. diamond, circle, cross is default) to indicate the points.

> plot([[3,2],[-2,3],[2,-1]],style=point,color=blue,symbol=circle);

[Maple Plot]

Exercise 3.4

Plot the following points using the color red and the diamond symbol: [1,4] , [-2,-3], [4,-5] and [-6,5].  Then connect the points with lines in a separate plot command.

Student Workspace 3.4

 

Answer 3.4

> plot([[1,4],[-2,-3],[4,-5],[-6,5]],style=point,color=red,symbol=diamond);

[Maple Plot]

> plot([[1,4],[-2,-3],[4,-5],[-6,5]],style=line,color=red,symbol=diamond);

[Maple Plot]

Combining Graphs of Expressions and Points: the display( ) command

A special plotting package called plots contains many additional graphing features. To use these commands, you need to execute the following line which loads plots . Recall, the colon at the end of the statement allows this line to be executed without displaying any distracting output. To see the contents of plots you can change the colon to a semicolon.

> with(plots):

Warning, the name changecoords has been redefined

The display( ) command allows you to combine graphs of expressions and points in the same picture. The first step is to name the individual picture components. IMPORTANT: Be sure to use a colon at the end of the line to suppress output (see first three lines below). The display( ) command is then used to do the actual plot (this ends with a semicolon).

> pict1:=plot([-3*x+5,9-x^2],x=-3..5,color=[green,red]):

> pict2:=plot([[-1,8],[4,-7]],style=point,color=blue,symbol=circle):

> display([pict1,pict2]);

[Maple Plot]

Alternatively we can list these three related plot commands in a single execution group by typing SHIFT-ENTER at end of each line.

> pict1:=plot([-3*x+5,9-x^2],x=-3..5,color=[green,red]):

> pict2:=plot([[-1,8],[4,-7]],style=point,color=blue,symbol=circle):

> display([pict1,pict2]);

[Maple Plot]

Exercise 3.5

Display a graph that contains both the function y = x^2+x-6 and its x and y intercepts, marked with circles.

Student Workspace 3.5

 

Answer 3.5

> pict4:=plot(x^2+x-6,x=-5..4,y=-8..8):

> pict5:=plot([[0,-6],[-3,0],[2,0]],style=point,symbol=circle, color=blue):

> display([pict4,pict5]);

[Maple Plot]

 

2. Plotting with Maple.

Use the Maple Help menu to do a Topic search on the plot command. A typical call to the plot command is

plot(f(x),x=a..b,y=c..d);

where f(x) is an expression in the variable x , a..b is the domain of the dependent variable x , and y=c..d tells Maple to only plot values of the dependent variable y in the range c..d . If you don't specify the range, Maple will "auto-scale" the output, and if you leave out the a..b part of the domain specification, Maple will use the domain -10..10 , but for an expression in x , you must tell Maple the name part, because otherwise it can't tell what is the variable in the expression.

Warning!!

In using the plot command and other commands which expect variables, it is necessary that x not be assigned a value. In problem 1, you assigned a value to x, so before you can execute the plot command above, you must unassigned the variable. One method of doing this is to type in the following command:

> x:='x';

x := 'x'

For example, to obtain a partial graph of the line y = 2*x-1 you could type plot(2*x-1,x);

To graph the line over the domain -.05..1.5 , type in plot(2*x-1,x=-0.5..1.5);

Experiment with the following variations of the plot command:

> plot(2*x-1,x=-0.5..1.5);

[Maple Plot]

> plot(2*x-1,x=-0.5..1.5,y);

[Maple Plot]

> plot(2*x-1,x=-0.5..1.5,y=-5..5);

[Maple Plot]

> plot(2*x-1,x=-0.5..1.5,-5..5);

[Maple Plot]

> plot(2*time-1,time=-0.5..1.5,'position');

[Maple Plot]

> plot(2*x-1,x=-0.5..1.5,scaling=constrained);

[Maple Plot]

> plot(2*x-1,x=-0.5..1.5,scaling=constrained,tickmarks=[1,3]);

[Maple Plot]

> plot(2*x-1,x=-0.5..1.5,scaling=constrained,tickmarks=[1,3],title=`Graph of the line y=2x-1`,color=blue);

[Maple Plot]

> plot([x^2,2*x-1],x=-0.5..1.5,title=`A parabola and one of its tangents`);

[Maple Plot]

Submission:

Plot the following functions:

(a) f(x) = 3

(b) f(x) = x^(-5)

(c) f(x) = x^2+1

(d) f(x) = x^2+x

(e) f(x) = x^3+x

(f) f(x) = x^4+3*x^2-1

Your graphs should be titled and have good choices of domain and range.

Submission worksheet: